package com.jason.quectel0805.fragments;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jason.quectel0805.R;
import com.jason.quectel0805.adapters.WeChatHomeAdapter;
import com.jason.quectel0805.entities.Conversation;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

/**
 * @author：Jason
 * @date：2022/8/9 15:16
 * @email：1129847330@qq.com
 * @description:
 */
public class WeChatHomeFragment extends Fragment {
    private RecyclerView rvHome;
    private List<Conversation> totallist = new ArrayList<>();
    private WeChatHomeAdapter weChatHomeAdapter;
    private static final String TAG = "jasonwan";

    public static Fragment newInstance() {
        return new WeChatHomeFragment();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_wechat_home, container, false);
        rvHome = view.findViewById(R.id.rv_wechat_home);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Log.d(TAG, "onActivityCreated: ");
        initRv();
        initData();
    }

    private void initData() {
        String avatarUrl = "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fblog%2F202107%2F23%2F20210723210602_a25c3.thumb.1000_0" +
                ".jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1662622956&t=58eb4834597c0b08b785ff275029f66c";
        for (int i = 0; i < 50; i++) {
            Conversation conversation = new Conversation();
            conversation.setAvatar(avatarUrl);
            conversation.setNickname("妈妈");
            conversation.setChatContent("生活费没了，赶紧打钱");
            totallist.add(conversation);
        }
        //weChatHomeAdapter.notifyDataSetChanged();
        weChatHomeAdapter.setList(totallist);

    }

    private void initRv() {
        rvHome.setLayoutManager(new LinearLayoutManager(getActivity()));
        weChatHomeAdapter = new WeChatHomeAdapter(totallist, getActivity());
        rvHome.setAdapter(weChatHomeAdapter);
    }
}